﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.Statistics.NM;
using MINERP.ComControls.Extension;
using MINERP.COM;

namespace MINERP.Statistics.Forms.ProfessionalReports
{
    public partial class FrmProdcutStatistcs : Form
    {
        public FrmProdcutStatistcs()
        {
            InitializeComponent();
        }

        private static FrmProdcutStatistcs instance = null;
        public static FrmProdcutStatistcs Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmProdcutStatistcs();
                }
                if (instance.IsDisposed)
                {
                    instance = new FrmProdcutStatistcs();
                }
                return instance;
            }
        }
        NMShopPruductPriceBll _bll = new NMShopPruductPriceBll();
        private void buttonOK_Click(object sender, EventArgs e)
        {
            buttonOK.Enabled = false;
            Cursor = Cursors.WaitCursor;
            try
            {

                DateTime startTime = dateEditStartTime.Value;
                DateTime endTime = dateEditEndTime.Value;
                gridControlRecord.DataSource = _bll.GetProductInfo(startTime, endTime).Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                buttonOK.Enabled = true;
                Cursor = Cursors.Default;
            }
        }

        private void FrmProdcutStatistcs_Load(object sender, EventArgs e)
        {
            dateEditStartTime.Value = DateTime.Now.Date;
        }

        private void buttonExport_Click(object sender, EventArgs e)
        {
            buttonExport.Enabled = false;
            Cursor = Cursors.WaitCursor;
            try
            {
                //DevGridViewExport.ExportToExcel("产品生产统计" + DateTime.Now.ToString("yyyyMMdd HHmmss"), gridViewRecord);
                DevControlExtension.ExportToExcel(gridControlRecord,this,"产品生产统计" + DateTime.Now.ToString("yyyyMMdd HHmmss"));
                //SaveFileDialog saveFileDialog = new SaveFileDialog();
                //saveFileDialog.Filter = "文本文件 (*.txt)|*.txt|pdf(*.pdf)|*.pdf|电子表格(*.xls)|*.xls|html(*.html)|*.html";
                ////saveFileDialog.AddExtension = true;
                //saveFileDialog.FilterIndex = 3;
                //saveFileDialog.RestoreDirectory = true;
                //if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                //{
                //    string fileName = saveFileDialog.FileName;
                //    if (saveFileDialog.OpenFile() != null)
                //    {
                //        switch (saveFileDialog.FilterIndex)
                //        {
                //            case 3:
                //                gridControlRecord.ExportToXls(fileName);
                //                return;
                //            case 4:
                //                gridControlRecord.ExportToHtml(fileName);
                //                return;
                //            case 2:
                //                gridControlRecord.ExportToPdf(fileName);
                //                return;
                //            case 1:
                //                this.gridControlRecord.ExportToText(fileName);
                //                return;
                //            default:
                //                break;
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                buttonExport.Enabled = true;
                Cursor = Cursors.Default;
            }
        }
    }
}
